package com.rgs.se.data.stack;

import java.time.LocalDateTime;
import java.util.Random;

/**
 * @author Ren Gaoshuai
 * @ClassName TestStack
 * @date 2022-04-07 21:39
 **/
public class TestStack {
    private static double testStack(Stack<Integer> stack,int opCount){
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i<opCount;i++){
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }

        for (int i = 0; i<opCount;i++){
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime)/1000000000.0;
    }

    public static void main(String[] args) {
        int opCount = 3000000;
        Stack<Integer> arrayStack = new ArrayStack<>();
        double d1 = testStack(arrayStack,opCount);

        Stack<Integer> listStack = new ListStack<>();
        double d2 = testStack(listStack,opCount);

        System.out.println(d1);
        System.out.println(d2);

    }
}
